home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Apple Shared Library Manager / ASLM Developer Tools / Interfaces / CIncludes / LibraryManager.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-19  |  46.6 KB  |  1,629 lines  |  [TEXT/MPS ]

  1. /*    File:        LibraryManager.h
  2.  
  3.     Contains:    Minimal declarations you need to use the ASLM.
  4.  
  5.     Copyright:    © 1991-1995 by Apple Computer, Inc., all rights reserved.
  6.  
  7.  
  8. */
  9.  
  10. #ifndef __LIBRARYMANAGER__
  11. #define __LIBRARYMANAGER__
  12.  
  13. #ifndef __STDDEF__
  14. #include <stddef.h>
  15. #endif
  16. #ifndef __STRING__
  17. #include <string.h>
  18. #endif
  19. #ifndef __TYPES__
  20. #include <Types.h>
  21. #endif
  22. #ifndef __CONDITIONALMACROS__
  23. #include <ConditionalMacros.h>
  24. #endif
  25.  
  26. //
  27. // Setup GENERATINGPOWERPC and GENERATING68K variables
  28. //
  29. #ifndef GENERATINGPOWERPC
  30.     #if defined(powerc) || defined(__powerc)
  31.         #define GENERATINGPOWERPC    1
  32.     #else
  33.         #define GENERATINGPOWERPC    0
  34.     #endif
  35. #endif
  36. #ifndef GENERATING68K
  37.     #if defined(powerc) || defined(__powerc)
  38.         #define GENERATING68K        0
  39.     #else
  40.         #define GENERATING68K        1
  41.     #endif
  42. #endif
  43.  
  44. #ifndef GENERATINGCFM
  45.     #define GENERATINGCFM    GENERATINGPOWERPC
  46. #endif
  47.  
  48. //
  49. //    Define the macros that handle adding an empty vtable slot at
  50. //    the beginning of the vtable for SCpp.
  51. //
  52. #define ASLM_COMPATIBLE
  53. #define ASLM_SCDECLARATION(className)
  54. #if defined(__SC__) || defined(THINK_CPLUS) || defined(__MRC__)
  55.     #if !NoDummyVTableSlot
  56.         #undef ASLM_COMPATIBLE
  57.         #undef ASLM_SCDECLARATION
  58.         #define ASLM_COMPATIBLE                                \
  59.             private:                                        \
  60.                 virtual        void DummyVirtualFunction();
  61.                 
  62.         #define ASLM_SCDECLARATION(className)        \
  63.         void className::DummyVirtualFunction() {}
  64.     #endif
  65. #endif
  66.  
  67. //
  68. //    Define SINGLEOBJECT to true if the compiler support SingleObject.
  69. //
  70. #if GENERATING68K && !defined(__SC__) || defined(__MWERKS__)
  71.     #define SINGLEOBJECT    1
  72. #else
  73.     #define SINGLEOBJECT    0
  74. #endif
  75.  
  76. //
  77. //    Define _CDECL as _cdecl only when using Symantec 68k products.
  78. //
  79. #if defined(__SC__) || defined(THINK_CPLUS) || defined(__MRC__)
  80.     #define _CDECL            _cdecl
  81. #else
  82.     #define _CDECL
  83. #endif
  84.  
  85. //
  86. //    Define the Volatile and VOLATILE macros based on the compiler.
  87. //
  88. #define VOLATILE(x)        ((void) &x)
  89. #if GENERATINGPOWERPC || defined(__SC__) || defined(THINK_CPLUS) || defined(__MWERKS__)
  90.     #define Volatile        volatile
  91. #else
  92.     #define Volatile
  93. #endif
  94.  
  95.  
  96. #undef SystemSixOrLater
  97. #define SystemSixOrLater    1
  98.  
  99.  
  100. /*******************************************************************************
  101. ** Some Typedefs and constants
  102. ********************************************************************************/
  103.  
  104. #ifndef NULL
  105. #define NULL        0
  106. #endif
  107.  
  108. //
  109. //    The following are parameter typedefs to force Symantec compilers to pass
  110. //    two byte parameters as four byte parameters so you can call MPW built
  111. //    shared libraries from Symantec built clients.
  112. //
  113. #if GENERATING68K
  114.     typedef    int                OSErrParm;
  115.     typedef unsigned int    BooleanParm;
  116.     typedef int                charParm;
  117.     typedef unsigned int    ucharParm;
  118.     typedef int                shortParm;
  119.     typedef unsigned int    ushortParm;
  120.     typedef long double        floatParm;
  121.     typedef long double        doubleParm;
  122. #else
  123.     typedef    OSErr            OSErrParm;
  124.     typedef Boolean            BooleanParm;
  125.     typedef char            charParm;
  126.     typedef unsigned char    ucharParm;
  127.     typedef short            shortParm;
  128.     typedef unsigned short    ushortParm;
  129.     typedef float            floatParm;
  130.     typedef double            doubleParm;
  131. #endif
  132.  
  133. /*******************************************************************************
  134. ** Some external routines
  135. ********************************************************************************/
  136.  
  137. #ifdef __cplusplus
  138. extern "C" {
  139. #endif
  140.     char* strcpy(char* s1, const char* s2);
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144.  
  145. /*******************************************************************************
  146. ** Error Constants
  147. ********************************************************************************/
  148.  
  149. #define kNoError                        0
  150. #define kASLMNotFoundErr                -3120
  151. #define kASLMNoParentErr                -3121
  152. #define kASLMParentNotFoundErr            -3122
  153. #define kASLMNotRelatedErr                -3123
  154. #define kASLMInvalidObjectErr            -3124
  155. #define kASLMPoolCorruptedErr            -3125
  156. #define kASLMOutOfMemoryErr                -3126
  157. #define kASLMCodeNotLoadedErr            -3127
  158. #define kASLMCouldNotLoadCodeErr        -3128
  159. #define kASLMFilePreflightedErr            -3129
  160. #define kASLMFileNotPreflightedErr        -3130
  161. #define kASLMFileNotFoundErr            -3131
  162. #define kASLMLibraryManagerNotLoadedErr    -3132
  163. #define kASLMDuplicateFoundErr            -3134
  164. #define kASLMSeedChangedErr                -3135
  165. #define kASLMUnconstructedObjectErr        -3136
  166. #define kASLMInternalErr                -3137
  167. #define kASLMVersionErr                    -3138
  168. #define kASLMFolderNotFoundErr            -3139
  169. #define kASLMFolderInUseErr                -3140
  170. #define kASLMResourceNotFoundErr        -3141
  171. #define kASLMInvalidSegmentNumberErr    -3142
  172. #define kASLMNotAllowedNowErr            -3155
  173. #define kASLMNotSupportedErr            -3167
  174.  
  175. /*******************************************************************************
  176. ** Typedefs
  177. ********************************************************************************/
  178.  
  179. //
  180. //    ASLM uses CDECLProcPtr instead of ProcPtr in all of its interfaces. It is the
  181. //    same as ProcPtr except when using SCpp. In this case it is declared as
  182. //    _cdecl so it will have C calling conventions instead of Cpp.
  183. //
  184. typedef long (* _CDECL CDECLProcPtr)();
  185.  
  186. typedef void*            GlobalWorld;
  187. #define kInvalidWorld    ((GlobalWorld)0)
  188.  
  189. typedef unsigned short    Version;
  190. typedef unsigned long    VersionParm;    // for passing a version as a paramter
  191. #define kAnyVersion        ((Version)0)
  192.  
  193. #define    TFunctionSetID    TClassID
  194. #define    TLibraryID        TClassID
  195.  
  196. #define    CastToFunctionSetID    CastToClassID    /* for casting a cstring to a TFunctionSetID */
  197. #define    CastToLibraryID        CastToClassID    /* for casting a cstring to a TLibraryID */
  198.  
  199. #define    FunctionSetID    CastToFunctionSetID    /* for casting a cstring to a TFunctionSetID */
  200. #define    LibraryID        CastToLibraryID        /* for casting a cstring to a TLibraryID */
  201. #ifndef ClassID        // make sure we don't conflict with MacApp
  202.     #define    ClassID        CastToClassID        /* for casting a cstring to a TLibraryID */
  203. #endif
  204.  
  205. /*******************************************************************************
  206. ** Forward class declarations
  207. ********************************************************************************/
  208.  
  209. #ifdef __cplusplus
  210.     class    TDynamic;
  211.     class    TLibraryManager;
  212.     class    TClassID;
  213.     class    TFunctionSetID;
  214.     class    TLibraryID;
  215.     class    TLibrary;
  216.     class    TFormattedStream;
  217.     class    TMemoryPool;
  218.     class    TStandardPool;
  219.     class    TLibraryFile;
  220.     class     TClassInfo;
  221.     class    TException;
  222.     class    TSimpleList;
  223.     class    TFileSpec;
  224. #else
  225.     typedef char* TClassID;
  226.     typedef void TDynamic;
  227.     typedef void TLibraryManager;
  228.     typedef void TFormattedStream;
  229.     typedef void TStandardPool;
  230.     typedef void TClassInfo;
  231.     typedef void TLibrary;
  232.     typedef void TMemoryPool;
  233. #endif
  234.  
  235.  
  236. /*******************************************************************************
  237. ** Memory definitions
  238. ********************************************************************************/
  239.  
  240. typedef int    ZoneType;
  241.  
  242. #define kSystemZone                ((ZoneType)1)
  243. #define kKernelZone                ((ZoneType)2)
  244. #define kApplicZone                ((ZoneType)3)
  245. #define kCurrentZone            ((ZoneType)4)
  246. #define kTempZone                ((ZoneType)5)
  247.  
  248. typedef int    MemoryType;
  249.  
  250. #define kNormalMemory            ((MemoryType)1)
  251. #define kHoldMemory                ((MemoryType)2)
  252. #define kLockMemory                ((MemoryType)3)
  253. #define kLockMemoryContiguous    ((MemoryType)4)
  254.  
  255. /*******************************************************************************
  256. ** ASLM Gestalt selector
  257. ********************************************************************************/
  258.  
  259. #define gestaltASLMPPC 'slmp'
  260. #define gestaltASLM68K 'aslm'
  261.  
  262. #if GENERATINGPOWERPC
  263.     #define gestaltASLM gestaltASLMPPC
  264. #else
  265.     #define gestaltASLM gestaltASLM68K
  266. #endif
  267.  
  268. /*
  269.     If the ASLM gestalt selector returns NULL then ASLM did not load properly
  270.     at boot time and is not available. Otherwise the version will be in the
  271.     upper 2 bytes of the result and lower 2 bits of the result will contain
  272.     information as described below.
  273. */
  274.  
  275. enum {
  276.     gestaltASLMVersionMask    = 0xffff0000,    /*    Version is in upper 2 bytes of result */
  277.     gestaltASLMPresentMask    = 0x0001,        /*    If first bit is set then ASLM was loaded
  278.                                                 at some point but may not be now. If you
  279.                                                 call InitLibraryManager, ASLM will load
  280.                                                 automatically, except at boot time, in
  281.                                                 which case it will set a flag so it stays
  282.                                                 loaded next time and then will reboot. */
  283.     gestaltASLMLoadedMask    = 0x0002        /*  If second bit is set then ASLM is
  284.                                                 currently loaded. */
  285. };
  286.  
  287. /*******************************************************************************
  288. ** Old interface definitions for backwards compatiblity.
  289. ********************************************************************************/
  290.  
  291. #ifndef SupportOldASLMInterfaces
  292. #define SupportOldASLMInterfaces 1
  293. #endif
  294.  
  295. #if SupportOldASLMInterfaces
  296.     //
  297.     // Old error code constants. New error code values are the same but the
  298.     // names were changed by adding "ASLM" to the front and "err" to the end.
  299.     //
  300.     #define kNotFound                        -3120
  301.     #define kNoParent                        -3121
  302.     #define kParentNotFound                    -3122
  303.     #define kNotRelated                        -3123
  304.     #define kInvalidObject                    -3124
  305.     #define kPoolCorrupted                    -3125
  306.     #define kOutOfMemory                    -3126
  307.     #define kCodeNotLoaded                    -3127
  308.     #define kCouldNotLoadCode                -3128
  309.     #define kFilePreflighted                -3129
  310.     #define kFileNotPreflighted                -3130
  311.     #define kFileNotFound                    -3131
  312.     #define kLibraryManagerNotLoaded        -3132
  313.     #define kDuplicateFound                    -3134
  314.     #define kSeedChanged                    -3135
  315.     #define kUnconstructedObject            -3136
  316.     #define kInternalError                    -3137
  317.     #define kVersionError                    -3138
  318.     #define kFolderNotFound                    -3139
  319.     #define kFolderInUse                    -3140
  320.     #define kResourceNotFound                -3141
  321.     #define kNotAllowedNow                    -3155
  322.     #define kNotSupported                    -3167
  323.  
  324.     //
  325.     //    The FSInfoGetParentID function was renamed to FSInfoGetInterfaceID
  326.     //
  327.     #define FSInfoGetParentID FSInfoGetInterfaceID
  328. #endif
  329.  
  330. /*******************************************************************************
  331. ** STACKOBJECTONLY: Use in a class declaration so the object can only be created
  332. ** on the stack. This makes the constructors and destructors much smaller since
  333. ** they know they will never have to new or delete memory.
  334. ********************************************************************************/
  335.  
  336. #define STACKOBJECTONLY                                                \
  337.     private:                                                        \
  338.                 void*    operator new(size_t) { return NULL; }        \
  339.                 void    operator delete(void*) {}
  340.  
  341. /*******************************************************************************
  342. ** Some "C" Global routines
  343. **
  344. ** InitLibraryManager initializes a client to use the ASLM. All clients
  345. ** must make this call except for ASLM libraries. CleanupLibraryManager
  346. ** should be called when the client is done using the ASLM.
  347. **
  348. ** GetLocalLibraryManager can be called after InitLibraryManager is called. If it
  349. ** returns NULL then InitLibraryManager failed.
  350. ********************************************************************************/
  351.  
  352. #ifdef __cplusplus
  353.     extern "C" {
  354. #endif
  355.  
  356. /*    -------------------------------------------------------------------------
  357.     These functions are for use by applications or stand-alone code 
  358.     resources only
  359.     ------------------------------------------------------------------------- */
  360.  
  361. #ifdef __cplusplus
  362.         
  363. OSErr                InitLibraryManager(size_t poolsize = 0, ZoneType = kCurrentZone,
  364.                                        MemoryType = kNormalMemory);
  365. void                CleanupLibraryManager();
  366.     
  367. #else
  368.  
  369. OSErr                InitLibraryManager(size_t poolsize, int zoneType, int memType);
  370. void                CleanupLibraryManager(void);
  371.     
  372. #endif
  373.  
  374. /*    -------------------------------------------------------------------------
  375.     Call FragmentIsNonApplicationASLMClient before calling InitLibraryManager
  376.     if you are writing a PowerPC CFM fragment that is not the main
  377.     application code fragment.
  378.     ------------------------------------------------------------------------- */
  379.  
  380. #if GENERATINGPOWERPC
  381.     void FragmentIsNonApplicationASLMClient();
  382. #endif
  383.  
  384.  
  385. /*    -------------------------------------------------------------------------
  386.     These functions can be used by any Shared Library Manager clients
  387.     ------------------------------------------------------------------------- */
  388.  
  389. #ifdef __cplusplus
  390.  
  391. Boolean                IsDerivedFrom(const void*, const TClassID&);
  392. const TClassID&        GetObjectsClassID(const void*);
  393. const TClassID&        GetObjectsParentClassID(const void*);
  394. unsigned short        GetObjectsVersion(const void*);
  395. unsigned short        GetObjectsMinVersion(const void*);
  396. size_t                GetObjectsSize(const void*);
  397. TLibrary*            GetObjectsLocalLibrary(const void*);
  398. TLibraryFile*        GetObjectsLocalLibraryFile(const void*);
  399. TStandardPool*        GetObjectsLocalPool(const void*);
  400. void                SetObjectsLocalPool(const void*, TStandardPool*);
  401.  
  402. void*                NewObject(const TClassID&, OSErr* = NULL,
  403.                               TMemoryPool* = NULL);
  404. void*                NewObjectWithParent(const TClassID&,
  405.                                         const TClassID& parentID,
  406.                                         OSErr* = NULL, TMemoryPool* = NULL);
  407. void*                NewObjectFromStream(const TFormattedStream&,
  408.                                         OSErr* = NULL, TMemoryPool* = NULL);
  409.  
  410. TClassInfo*         GetClassInfo(const TClassID&, OSErr* = NULL);
  411.  
  412. OSErr                VerifyClass(const TClassID&, const TClassID& parentID);
  413. void*                CastObject(const void*, const TClassID& parentID, OSErr* = NULL);
  414. void*                CastToMainObject(const void*);
  415.  
  416. OSErr                LoadClass(const TClassID&, BooleanParm forceAll);
  417. OSErr                UnloadClass(const TClassID&);
  418. Boolean                IsClassLoaded(const TClassID&);
  419.  
  420. OSErr                LoadFunctionSet(const TFunctionSetID&, BooleanParm forceAll);
  421. OSErr                UnloadFunctionSet(const TFunctionSetID&);
  422. Boolean                IsFunctionSetLoaded(const TFunctionSetID&);
  423.  
  424. CDECLProcPtr        GetFunctionPointer(const TFunctionSetID&, const char* funcName,
  425.                                        OSErr* = NULL);
  426. CDECLProcPtr        GetIndexedFunctionPointer(const TFunctionSetID&, unsigned int index,
  427.                                               OSErr* = NULL);
  428.  
  429. OSErr                LoadLibraries(BooleanParm forceAll = true,
  430.                                   BooleanParm doSelf = true);
  431. OSErr                UnloadLibraries();
  432. void                ResetFunctionSet(const TFunctionSetID* = NULL);
  433.         
  434. Boolean                TraceLogOn();
  435. Boolean                TraceLogOff();
  436.  
  437. void                RegisterDynamicObject(TDynamic*);
  438. void                UnregisterDynamicObject(TDynamic*);
  439.     
  440. TLibraryManager*    GetLocalLibraryManager();
  441.     
  442. TStandardPool*        GetLocalPool();
  443. void                SetLocalPool(TStandardPool*);
  444. TStandardPool*        GetClientPool();
  445. TStandardPool*        GetDefaultPool();
  446. void                SetDefaultPool(TStandardPool*);
  447. TStandardPool*        GetSystemPool();
  448.     
  449. #else
  450.     
  451. void*                NewObject(const TClassID, OSErr*, TStandardPool*);
  452. void*                NewObjectWithParent(const TClassID, const TClassID parentID,
  453.                                         OSErr*, TMemoryPool*);
  454. void*                NewObjectFromStream(const TFormattedStream*, OSErr*,
  455.                                         TMemoryPool*);
  456.  
  457. TClassInfo*         GetClassInfo(const TClassID, OSErr*);
  458.  
  459. OSErr                VerifyClass(const TClassID, const TClassID parentID);
  460. void*                CastObject(const void*, const TClassID parentID, OSErr*);
  461. void*                CastToMainObject(const void*);
  462.  
  463. OSErr                LoadClass(const TClassID, BooleanParm forceAll);
  464. OSErr                UnloadClass(const TClassID);
  465. Boolean                IsClassLoaded(const TClassID);
  466.  
  467. OSErr                LoadFunctionSet(const TFunctionSetID, BooleanParm forceAll);
  468. OSErr                UnloadFunctionSet(const TFunctionSetID);
  469. Boolean                IsFunctionSetLoaded(const TFunctionSetID);
  470.  
  471. ProcPtr                GetFunctionPointer(const TFunctionSetID, const char* funcName,
  472.                                        OSErr*);
  473. ProcPtr                GetIndexedFunctionPointer(const TFunctionSetID, unsigned int index,
  474.                                               OSErr*);
  475.  
  476. OSErr                LoadLibraries(BooleanParm forceAll, BooleanParm doSelf);
  477. OSErr                UnloadLibraries(void);
  478. void                ResetFunctionSet(const TFunctionSetID);
  479.         
  480. Boolean                TraceLogOn();
  481. Boolean                TraceLogOff();
  482.  
  483. TLibraryManager*    GetLocalLibraryManager(void);
  484.  
  485. TStandardPool*        GetLocalPool();
  486. void                SetLocalPool(TStandardPool*);
  487. TStandardPool*        GetClientPool();
  488. TStandardPool*        GetDefaultPool();
  489. void                SetDefaultPool(TStandardPool*);
  490. TStandardPool*        GetSystemPool();
  491.  
  492. #endif
  493.  
  494. /*
  495.     These routines are declared in LibraryManagerUtilities.h, but are needed
  496.     for the inlines below.
  497. */
  498.  
  499. void* SLMNewOperator(size_t, TMemoryPool*);
  500. void SLMDeleteOperator(void*);
  501.  
  502. #ifdef __cplusplus
  503. }
  504.  
  505.  
  506. /*******************************************************************************
  507. ** CLASS TSimpleDynamic
  508. **
  509. ** A base class for shared-library classes that has no virtual functions.  This
  510. ** class is NOT shared, since it is intended to be a trivial class that just
  511. ** forces the VTable to be at the front of the object.
  512. ********************************************************************************/
  513.  
  514. #if SINGLEOBJECT
  515. class TSimpleDynamic : public SingleObject
  516. #else
  517. class TSimpleDynamic
  518. #endif
  519. {
  520.     ASLM_COMPATIBLE
  521.  
  522.     public:
  523.         virtual                  ~ _CDECL TSimpleDynamic();
  524.         
  525.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  526.                                     { return SLMNewOperator(size, pool); }
  527.                 void*            operator new(size_t size)                        // from default pool
  528.                                     { return SLMNewOperator(size, 0); }
  529.                 void            operator delete(void* obj, size_t)
  530.                                     { SLMDeleteOperator(obj); }
  531.  
  532.                 const TClassID&    GetObjectsClassID() const;
  533.                 const TClassID&    GetObjectsParentClassID() const;
  534.                 unsigned short    GetObjectsVersion() const;
  535.                 unsigned short    GetObjectsMinVersion() const;
  536.                 size_t            GetObjectsSize() const;
  537.                 TLibrary*        GetObjectsLocalLibrary() const;
  538.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  539.                 TStandardPool*    GetObjectsLocalPool() const;
  540.                 void            SetObjectsLocalPool(TStandardPool*) const;
  541.     
  542.                 Boolean            IsDerivedFrom(const TClassID&) const;
  543.                 
  544.     protected:
  545.                                   _CDECL TSimpleDynamic();
  546.  
  547.     private:
  548.                                 TSimpleDynamic(const TSimpleDynamic&);
  549.                 void            operator=(const TSimpleDynamic&);
  550. };
  551.  
  552. /*******************************************************************************
  553. ** CLASS TDynamic
  554. **
  555. ** The base class for shared-library classes with a set of common capabilities.
  556. ** This class provides the same capabilities as TStdDynamic.
  557. ********************************************************************************/
  558.  
  559. typedef int    TraceControlType;
  560.  
  561. #define kTraceStatus    ((TraceControlType)1)
  562. #define kTraceOn        ((TraceControlType)2)
  563. #define kTraceOff        ((TraceControlType)3)
  564.  
  565. #define kTDynamicID "!$dyna,1.2"
  566.  
  567. #if SINGLEOBJECT
  568. class TDynamic : public SingleObject
  569. #else
  570. class TDynamic
  571. #endif
  572. {
  573.     ASLM_COMPATIBLE
  574.  
  575.     public:
  576.         virtual                  ~ _CDECL TDynamic();
  577.         
  578.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  579.                                     { return SLMNewOperator(size, pool); }
  580.                 void*            operator new(size_t size)                        // from default pool
  581.                                     { return SLMNewOperator(size, 0); }
  582.                 void            operator delete(void* obj, size_t)
  583.                                     { SLMDeleteOperator(obj); }
  584.                                     
  585.  
  586.         const TClassID&            GetObjectsClassID() const;
  587.         const TClassID&            GetObjectsParentClassID() const;
  588.                 unsigned short    GetObjectsVersion() const;
  589.                 unsigned short    GetObjectsMinVersion() const;
  590.                 size_t            GetObjectsSize() const;
  591.                 TLibrary*        GetObjectsLocalLibrary() const;
  592.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  593.                 TStandardPool*    GetObjectsLocalPool() const;
  594.                 void            SetObjectsLocalPool(TStandardPool*) const;
  595.  
  596.         virtual Boolean            _CDECL IsValid() const;
  597.         
  598.         virtual    OSErr            _CDECL Inflate(TFormattedStream&);
  599.         virtual OSErr            _CDECL Flatten(TFormattedStream&) const;
  600.         virtual TDynamic*        _CDECL Clone(TStandardPool*) const;
  601.         
  602.         virtual    char*            _CDECL GetVerboseName(char*) const;
  603.         virtual    void            _CDECL Dump() const;
  604.         
  605.                 void            _CDECL Trace(char *formatStr, ...) const;
  606.         virtual    Boolean            _CDECL TraceControl(TraceControlType) const;
  607.                 Boolean            IsTraceOn() const;    
  608.                 Boolean            TraceOn() const;
  609.                 Boolean            TraceOff() const;
  610.     
  611.                 Boolean            IsDerivedFrom(const TClassID&) const;
  612.                 
  613.     protected:
  614.                                   _CDECL TDynamic();
  615.  
  616.     private:
  617.                                 TDynamic(const TDynamic&);
  618.                 void            operator=(const TDynamic&);
  619. };
  620.  
  621. /*    -------------------------------------------------------------------------
  622.     Inline methods for TDynamic
  623.     ------------------------------------------------------------------------- */
  624.  
  625.     inline Boolean TDynamic::IsTraceOn() const
  626.     {
  627.         return TraceControl(kTraceStatus);
  628.     }
  629.  
  630.     inline Boolean TDynamic::TraceOn() const
  631.     {
  632.         return TraceControl(kTraceOn);
  633.     }
  634.  
  635.     inline Boolean TDynamic::TraceOff() const
  636.     {
  637.         return TraceControl(kTraceOff);
  638.     }
  639.  
  640. /*******************************************************************************
  641. ** CLASS MDynamic
  642. **
  643. ** A base class for shared-library classes, which has one 1 virtual function (the
  644. ** destructor).  This class is NOT shared, since it is intended to be a trivial class
  645. ** that can be used to force the VTable to be at the front of the object for
  646. ** mixin classes.
  647. ********************************************************************************/
  648.  
  649. class MDynamic
  650. {
  651.     ASLM_COMPATIBLE
  652.  
  653.     public:
  654.         virtual                  ~_CDECL MDynamic();
  655.         
  656.     protected:
  657.                                   _CDECL MDynamic();
  658.  
  659.     private:
  660.                                 MDynamic(const MDynamic&);
  661.                 void            operator=(const MDynamic&);
  662. };
  663.  
  664. /*******************************************************************************
  665. ** CLASS TStdDynamic
  666. **
  667. ** The base class for shared-library classes with a set of common capabilities.
  668. ** This class provides the same capabilities as TDynamic below, but is for
  669. ** classes that you don't want to descend from SingleObject.
  670. ********************************************************************************/
  671.  
  672. #define kTStdDynamicID "!$sdyn,1.2"
  673.  
  674. class TStdDynamic
  675. {
  676.     ASLM_COMPATIBLE
  677.  
  678.     public:
  679.         virtual                  ~ _CDECL TStdDynamic();
  680.         
  681.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  682.                                     { return SLMNewOperator(size, pool); }
  683.                 void*            operator new(size_t size)                        // from default pool
  684.                                     { return SLMNewOperator(size, 0); }
  685.                 void            operator delete(void* obj, size_t)
  686.                                     { SLMDeleteOperator(obj); }
  687.                                     
  688.  
  689.         const TClassID&            GetObjectsClassID() const;
  690.                 unsigned short    GetObjectsVersion() const;
  691.                 unsigned short    GetObjectsMinVersion() const;
  692.                 size_t            GetObjectsSize() const;
  693.                 TLibrary*        GetObjectsLocalLibrary() const;
  694.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  695.                 TStandardPool*    GetObjectsLocalPool() const;
  696.                 void            SetObjectsLocalPool(TStandardPool*) const;
  697.  
  698.         virtual Boolean            _CDECL IsValid() const;
  699.         
  700.         virtual    OSErr            _CDECL Inflate(TFormattedStream&);
  701.         virtual OSErr            _CDECL Flatten(TFormattedStream&) const;
  702.         virtual TDynamic*        _CDECL Clone(TStandardPool*) const;
  703.         
  704.         virtual    char*            _CDECL GetVerboseName(char*) const;
  705.         virtual    void            _CDECL Dump() const;
  706.         
  707.                 void            _CDECL Trace(char *formatStr, ...) const;
  708.         virtual    Boolean            _CDECL TraceControl(TraceControlType) const;
  709.                 Boolean            IsTraceOn() const;    
  710.                 Boolean            TraceOn() const;
  711.                 Boolean            TraceOff() const;
  712.     
  713.                 Boolean            IsDerivedFrom(const TClassID&) const;
  714.                 
  715.     protected:
  716.                                   _CDECL TStdDynamic();
  717.  
  718.     private:
  719.                                 TStdDynamic(const TDynamic&);
  720.                 void            operator=(const TDynamic&);
  721. };
  722.  
  723. /*    -------------------------------------------------------------------------
  724.     Inline methods for TStdDynamic
  725.     ------------------------------------------------------------------------- */
  726.     
  727.     inline Boolean TStdDynamic::IsTraceOn() const
  728.     {
  729.         return TraceControl(kTraceStatus);
  730.     }
  731.  
  732.     inline Boolean TStdDynamic::TraceOn() const
  733.     {
  734.         return TraceControl(kTraceOn);
  735.     }
  736.  
  737.     inline Boolean TStdDynamic::TraceOff() const
  738.     {
  739.         return TraceControl(kTraceOff);
  740.     }
  741.  
  742. /*******************************************************************************
  743. ** CLASS TStdSimpleDynamic
  744. **
  745. ** A base class for shared-library classes that has no virtual functions.  This
  746. ** class is NOT shared, since it is intended to be a trivial class that just
  747. ** forces the VTable to be at the front of the object.
  748. ********************************************************************************/
  749.  
  750. class TStdSimpleDynamic
  751. {
  752.     ASLM_COMPATIBLE
  753.  
  754.     public:
  755.         virtual                  ~ _CDECL TStdSimpleDynamic();
  756.         
  757.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  758.                                     { return SLMNewOperator(size, pool); }
  759.                 void*            operator new(size_t size)                        // from default pool
  760.                                     { return SLMNewOperator(size, 0); }
  761.                 void            operator delete(void* obj, size_t)
  762.                                     { SLMDeleteOperator(obj); }
  763.  
  764.                 const TClassID&    GetObjectsClassID() const;
  765.                 unsigned short    GetObjectsVersion() const;
  766.                 unsigned short    GetObjectsMinVersion() const;
  767.                 size_t            GetObjectsSize() const;
  768.                 TLibrary*        GetObjectsLocalLibrary() const;
  769.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  770.                 TStandardPool*    GetObjectsLocalPool() const;
  771.                 void            SetObjectsLocalPool(TStandardPool*) const;
  772.     
  773.                 Boolean            IsDerivedFrom(const TClassID&) const;
  774.                 
  775.     protected:
  776.                                   _CDECL TStdSimpleDynamic();
  777.  
  778.     private:
  779.                                 TStdSimpleDynamic(const TStdSimpleDynamic&);
  780.                 void            operator=(const TStdSimpleDynamic&);
  781. };
  782.  
  783. #if defined(__SC__) || defined(__MRC__)
  784.  
  785. /*******************************************************************************
  786. ** CLASS TSCSimpleDynamic
  787. **
  788. ** A base class for shared-library classes that has no virtual functions.  This
  789. ** class is NOT shared, since it is intended to be a trivial class that just
  790. ** forces the VTable to be at the front of the object, and override new to
  791. ** use the ASLM operators. It is used as a simple base class for Symantec C++ objects.
  792. ** This is the normal subclass for Symantec C++ objects that are not going to 
  793. ** intermix with MPW C++ objects.
  794. ********************************************************************************/
  795.  
  796. class TSCSimpleDynamic
  797. {
  798.     ASLM_COMPATIBLE
  799.  
  800.     public:
  801.         virtual                  ~TSCSimpleDynamic();
  802.         
  803.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  804.                                     { return SLMNewOperator(size, pool); }
  805.                 void*            operator new(size_t size)                        // from default pool
  806.                                     { return SLMNewOperator(size, 0); }
  807.                 void            operator delete(void* obj, size_t)
  808.                                     { SLMDeleteOperator(obj); }
  809.  
  810.                 const TClassID&    GetObjectsClassID() const;
  811.                 const TClassID&    GetObjectsParentClassID() const;
  812.                 unsigned short    GetObjectsVersion() const;
  813.                 unsigned short    GetObjectsMinVersion() const;
  814.                 size_t            GetObjectsSize() const;
  815.                 TLibrary*        GetObjectsLocalLibrary() const;
  816.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  817.                 TStandardPool*    GetObjectsLocalPool() const;
  818.                 void            SetObjectsLocalPool(TStandardPool*) const;
  819.     
  820.                 Boolean            IsDerivedFrom(const TClassID&) const;
  821.                 
  822.     protected:
  823.                                   TSCSimpleDynamic();
  824.  
  825.     private:
  826.                                 TSCSimpleDynamic(const TSCSimpleDynamic&);
  827.                 void            operator=(const TSCSimpleDynamic&);
  828. };
  829.  
  830. /*******************************************************************************
  831. ** CLASS TSCDynamic
  832. **
  833. ** The base class for shared-library classes with a set of common capabilities.
  834. ** This class provides the same capabilities as TStdDynamic.  It is only for
  835. ** Symantec C++ implementations
  836. ********************************************************************************/
  837.  
  838. #define kTSCDynamicID "!$scdy,1.2"
  839.  
  840. class TSCDynamic
  841. {
  842.     ASLM_COMPATIBLE
  843.  
  844.     public:
  845.         virtual                  ~ _cdecl TSCDynamic();
  846.         
  847.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  848.                                     { return SLMNewOperator(size, pool); }
  849.                 void*            operator new(size_t size)                        // from default pool
  850.                                     { return SLMNewOperator(size, 0); }
  851.                 void            operator delete(void* obj, size_t)
  852.                                     { SLMDeleteOperator(obj); }
  853.  
  854.         const TClassID&            GetObjectsClassID() const;
  855.         const TClassID&            GetObjectsParentClassID() const;
  856.                 unsigned short    GetObjectsVersion() const;
  857.                 unsigned short    GetObjectsMinVersion() const;
  858.                 size_t            GetObjectsSize() const;
  859.                 TLibrary*        GetObjectsLocalLibrary() const;
  860.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  861.                 TStandardPool*    GetObjectsLocalPool() const;
  862.                 void            SetObjectsLocalPool(TStandardPool*) const;
  863.  
  864.         virtual Boolean            _cdecl IsValid() const;
  865.         
  866.         virtual    OSErr            _cdecl Inflate(TFormattedStream&);
  867.         virtual OSErr            _cdecl Flatten(TFormattedStream&) const;
  868.         virtual TSCDynamic*        _cdecl Clone(TStandardPool*) const;
  869.         
  870.         virtual    char*            _cdecl GetVerboseName(char*) const;
  871.         virtual    void            _cdecl Dump() const;
  872.         
  873.                 void            _cdecl Trace(char *formatStr, ...) const;
  874.         virtual    Boolean            _cdecl TraceControl(TraceControlType) const;
  875.                 Boolean            IsTraceOn() const;    
  876.                 Boolean            TraceOn() const;
  877.                 Boolean            TraceOff() const;
  878.     
  879.                 Boolean            IsDerivedFrom(const TClassID&) const;
  880.                 
  881.     protected:
  882.                                   _cdecl TSCDynamic();
  883.  
  884.     private:
  885.                                 TSCDynamic(const TSCDynamic&);
  886.                 void            operator=(const TSCDynamic&);
  887. };
  888.  
  889. /*    -------------------------------------------------------------------------
  890.     Inline methods for TSCDynamic
  891.     ------------------------------------------------------------------------- */
  892.  
  893.     inline Boolean TSCDynamic::IsTraceOn() const
  894.     {
  895.         return TraceControl(kTraceStatus);
  896.     }
  897.  
  898.     inline Boolean TSCDynamic::TraceOn() const
  899.     {
  900.         return TraceControl(kTraceOn);
  901.     }
  902.  
  903.     inline Boolean TSCDynamic::TraceOff() const
  904.     {
  905.         return TraceControl(kTraceOff);
  906.     }
  907.     
  908. #endif    /* __SC__ */
  909. #endif    /* __cplusplus */
  910.  
  911. /*******************************************************************************
  912. ** Class TClassID, TFunctionSetID, and TLibraryID
  913. **
  914. ** TFunctionSetID and TLibraryID are typedef'd to be the same as TClassID
  915. ********************************************************************************/
  916.  
  917. #define kMaxClassIDSize        255
  918.  
  919. #ifdef __cplusplus
  920.  
  921. const TClassID& CastToClassID(const char* str);    // cast a char* to a TClassID
  922.  
  923. Boolean operator==(const TClassID&, const char *);
  924. Boolean operator!=(const TClassID&, const char *);
  925. Boolean operator==(const char *, const TClassID&);
  926. Boolean operator!=(const char *, const TClassID&);
  927.  
  928. class TClassID
  929. {
  930.     public:
  931.         void*        operator new(size_t, size_t strLen, TMemoryPool* thePool = NULL)
  932.                     {
  933.                         return SLMNewOperator(strLen+1, thePool);
  934.                     }
  935.  
  936.         void*        operator new(size_t)
  937.                     {
  938.                         return SLMNewOperator(kMaxClassIDSize+1, NULL);
  939.                     }
  940.                         
  941.         void        operator delete(void* obj, size_t)
  942.                         { SLMDeleteOperator(obj); }
  943.  
  944.                     TClassID();
  945.                     TClassID(const TClassID&);
  946.  
  947.                     operator const char*() const;        // cast to a const char *
  948.  
  949.         Version        _CDECL ExtractVersion() const;
  950.         size_t        _CDECL GetLength() const;
  951.         
  952.         TClassID&    operator=(const TClassID&);
  953.  
  954.         Boolean        _CDECL operator==(const TClassID&) const;
  955.         Boolean        operator!=(const TClassID&) const;
  956.  
  957.     private:
  958.         char                fClassIDStr[kMaxClassIDSize + 1];
  959. };
  960.  
  961. /*    -------------------------------------------------------------------------
  962.     Inline methods for TClassID
  963.     ------------------------------------------------------------------------- */
  964.  
  965.     //
  966.     // constructors
  967.     //
  968.  
  969.     inline TClassID::TClassID()
  970.     {
  971.         fClassIDStr[0] = 0;
  972.     }
  973.     
  974.     inline TClassID::TClassID(const TClassID& classID)
  975.     {
  976.         strcpy(fClassIDStr, classID.fClassIDStr);
  977.     }
  978.  
  979.     //
  980.     // cast operators
  981.     //
  982.  
  983.     inline const TClassID& CastToClassID(const char* str)
  984.     {
  985.         return *(const TClassID*)str;
  986.     }
  987.     
  988.     inline TClassID::operator const char *() const
  989.     {
  990.         return fClassIDStr;
  991.     }
  992.  
  993.     //
  994.     // compare operators
  995.     //
  996.     
  997.     inline Boolean TClassID::operator!=(const TClassID& classID) const
  998.     {
  999.         return !(*this == classID);
  1000.     }
  1001.     
  1002.     inline Boolean operator!=(const TClassID& id1, const char *id2)
  1003.     {
  1004.         return !(id1 == CastToClassID(id2));
  1005.     }
  1006.  
  1007.     inline Boolean operator!=(const char *id1, const TClassID& id2)
  1008.     {
  1009.         return !(id2 == CastToClassID(id1));
  1010.     }
  1011.     
  1012.     inline Boolean operator==(const TClassID& id1, const char *id2)
  1013.     {
  1014.         return (id1 == CastToClassID(id2));
  1015.     }
  1016.     
  1017.     inline Boolean operator==(const char *id1, const TClassID& id2)
  1018.     {
  1019.         return (id2 == CastToClassID(id1));
  1020.     }
  1021.  
  1022.     //
  1023.     // assignment operators
  1024.     //
  1025.     
  1026.     inline TClassID& TClassID::operator=(const TClassID& classID)
  1027.     {
  1028.         strcpy(fClassIDStr, classID.fClassIDStr);
  1029.         return *this;
  1030.     }
  1031.     
  1032. #endif
  1033.  
  1034. /*******************************************************************************
  1035. ** Class TLibraryManager
  1036. **
  1037. ** The user's interface to the world! 
  1038. ********************************************************************************/
  1039.  
  1040. #ifdef __cplusplus
  1041.  
  1042. #define kTLibraryManagerID "!$lmgr,1.2"
  1043.  
  1044. class TLibraryManager : public TDynamic 
  1045. {
  1046.  
  1047.     private:
  1048.         virtual                    ~ _CDECL TLibraryManager();
  1049.                                 _CDECL TLibraryManager(TStandardPool* = NULL, TLibraryFile* = NULL);
  1050.  
  1051.     public:
  1052.         virtual    void            _CDECL Dump() const;
  1053.  
  1054.         // New Methods
  1055.         
  1056.         virtual    void*            _CDECL NewObject(const TClassID& classID,
  1057.                                     OSErr* = NULL, TMemoryPool* = NULL) const;
  1058.         virtual    void*            _CDECL NewObject(const TClassID& classID, const TClassID& baseClassID,
  1059.                                     OSErr* = NULL, TMemoryPool* = NULL) const;
  1060.         virtual    void*            _CDECL NewObject(const TFormattedStream&,
  1061.                                     OSErr* = NULL, TMemoryPool* = NULL) const;
  1062.  
  1063.         virtual TClassInfo*     _CDECL GetClassInfo(const TClassID&, OSErr* = NULL) const;
  1064.  
  1065.         virtual OSErr            _CDECL VerifyClass(const TClassID& classID, const TClassID& baseClassID) const;
  1066.         virtual void*            _CDECL CastObject(const void* obj, const TClassID& parentID,
  1067.                                                 OSErr* = NULL) const;
  1068.         virtual void*            _CDECL CastToMainObject(const void* obj) const;
  1069.         
  1070.         virtual OSErr            _CDECL LoadClass(const TClassID&, BooleanParm loadAll = false);
  1071.         virtual OSErr            _CDECL UnloadClass(const TClassID&);
  1072.         virtual Boolean            _CDECL IsClassLoaded(const TClassID&) const;
  1073.  
  1074.                 OSErr            LoadFunctionSet(const TFunctionSetID&, BooleanParm loadAll = false);
  1075.                 OSErr            UnloadFunctionSet(const TFunctionSetID&);
  1076.                 Boolean            IsFunctionSetLoaded(const TFunctionSetID&) const;
  1077.         
  1078.         virtual CDECLProcPtr    _CDECL GetFunctionPointer(const TFunctionSetID&,
  1079.                                                    const char* funcName,
  1080.                                                    OSErr* = NULL);
  1081.         virtual CDECLProcPtr    _CDECL GetFunctionPointer(const TFunctionSetID&,
  1082.                                                    unsigned int index,
  1083.                                                    OSErr* = NULL);
  1084.         
  1085.         virtual OSErr            _CDECL LoadLibraries(BooleanParm forceAll = true,
  1086.                                                    BooleanParm doSelf = true);
  1087.         virtual OSErr            _CDECL UnloadLibraries();
  1088.         virtual void            _CDECL ResetFunctionSet(const TFunctionSetID* = NULL);
  1089.         
  1090.         virtual Boolean            _CDECL TraceLogOn();
  1091.         virtual Boolean            _CDECL TraceLogOff();
  1092.         
  1093.         virtual    void            _CDECL RegisterDynamicObject(TDynamic*);
  1094.         virtual    void            _CDECL UnregisterDynamicObject(TDynamic*);
  1095.  
  1096.                 void            SetObjectPool(TStandardPool*);
  1097.                 TStandardPool*    GetObjectPool() const;
  1098.                 void            SetDefaultPool(TStandardPool*);
  1099.                 TStandardPool*    GetDefaultPool() const;
  1100.                 GlobalWorld        _CDECL GetGlobalWorld() const;
  1101.         virtual    TLibrary*        _CDECL GetLibrary() const;
  1102.         virtual    TLibraryFile*    _CDECL GetLibraryFile() const;
  1103.  
  1104.     private:
  1105.                                 TLibraryManager(const TLibraryManager&);
  1106.                 void            operator=(const TLibraryManager&);
  1107.     private:        
  1108.         TStandardPool*            fPool;            // pool used for new objects and local pool
  1109.         TLibraryFile*            fLibraryFile;
  1110.         TStandardPool*            fDefaultPool;
  1111.         GlobalWorld                fGlobalWorld;
  1112.  
  1113. };
  1114.  
  1115. /*    -------------------------------------------------------------------------
  1116.     Inline Methods for TLibraryManager
  1117.     ------------------------------------------------------------------------- */
  1118.     
  1119.     inline OSErr TLibraryManager::LoadFunctionSet(const TFunctionSetID& functionSetID, BooleanParm loadAll)
  1120.     {
  1121.         return LoadClass(functionSetID, loadAll);
  1122.     }
  1123.     
  1124.     inline OSErr TLibraryManager::UnloadFunctionSet(const TFunctionSetID& functionSetID)
  1125.     {
  1126.         return UnloadClass(functionSetID);
  1127.     }
  1128.     
  1129.     inline Boolean TLibraryManager::IsFunctionSetLoaded(const TFunctionSetID& functionSetID) const
  1130.     {
  1131.         return IsClassLoaded(functionSetID);
  1132.     }
  1133.     
  1134.     inline TStandardPool* TLibraryManager::GetObjectPool() const
  1135.     {
  1136.         return fPool;
  1137.     }
  1138.     
  1139.     inline void TLibraryManager::SetObjectPool(TStandardPool* thePool)
  1140.     {
  1141.         fPool = thePool;
  1142.     }
  1143.         
  1144.     inline TStandardPool* TLibraryManager::GetDefaultPool() const
  1145.     {
  1146.         return fDefaultPool;
  1147.     }
  1148.  
  1149.     inline void TLibraryManager::SetDefaultPool(TStandardPool* thePool)
  1150.     {
  1151.         fDefaultPool = thePool;
  1152.     }
  1153.     
  1154.     inline GlobalWorld TLibraryManager::GetGlobalWorld() const
  1155.     {
  1156.         return fGlobalWorld;
  1157.     }
  1158.  
  1159. /*    -------------------------------------------------------------------------
  1160.     Inline for IsDerivedFrom
  1161.     ------------------------------------------------------------------------- */
  1162.  
  1163.     inline Boolean IsDerivedFrom(const void* obj, const TClassID& id)
  1164.     {
  1165.         return (GetLocalLibraryManager()->CastObject(obj, id) != NULL);
  1166.     }
  1167.  
  1168. /*    -------------------------------------------------------------------------
  1169.     Inline methods for TDynamic
  1170.     ------------------------------------------------------------------------- */
  1171.  
  1172.     inline Boolean TDynamic::IsDerivedFrom(const TClassID& id) const
  1173.     {
  1174.         return ::IsDerivedFrom(this, id);
  1175.     }
  1176.  
  1177.     inline const TClassID& TDynamic::GetObjectsClassID() const
  1178.     {
  1179.         return ::GetObjectsClassID(this);
  1180.     }
  1181.  
  1182.     inline const TClassID& TDynamic::GetObjectsParentClassID() const
  1183.     {
  1184.         return ::GetObjectsParentClassID(this);
  1185.     }
  1186.  
  1187.     inline unsigned short TDynamic::GetObjectsVersion() const
  1188.     {
  1189.         return ::GetObjectsVersion(this);
  1190.     }
  1191.  
  1192.     inline unsigned short TDynamic::GetObjectsMinVersion() const
  1193.     {
  1194.         return ::GetObjectsMinVersion(this);
  1195.     }
  1196.  
  1197.     inline size_t TDynamic::GetObjectsSize() const
  1198.     {
  1199.         return ::GetObjectsSize(this);
  1200.     }
  1201.  
  1202.     inline TLibrary* TDynamic::GetObjectsLocalLibrary() const
  1203.     {
  1204.         return ::GetObjectsLocalLibrary(this);
  1205.     }
  1206.  
  1207.     inline TLibraryFile* TDynamic::GetObjectsLocalLibraryFile() const
  1208.     {
  1209.         return ::GetObjectsLocalLibraryFile(this);
  1210.     }
  1211.  
  1212.     inline TStandardPool* TDynamic::GetObjectsLocalPool() const
  1213.     {
  1214.         return ::GetObjectsLocalPool(this);
  1215.     }
  1216.  
  1217.     inline void TDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1218.     {
  1219.         ::SetObjectsLocalPool(this, pool);
  1220.     }
  1221.     
  1222. /*    -------------------------------------------------------------------------
  1223.     Inline methods for TSimpleDynamic
  1224.     ------------------------------------------------------------------------- */
  1225.  
  1226.     inline const TClassID& TSimpleDynamic::GetObjectsClassID() const
  1227.     {
  1228.         return ((const TDynamic*)this)->GetObjectsClassID();
  1229.     }
  1230.  
  1231.     inline const TClassID& TSimpleDynamic::GetObjectsParentClassID() const
  1232.     {
  1233.         return ((const TDynamic*)this)->GetObjectsParentClassID();
  1234.     }
  1235.  
  1236.     inline unsigned short TSimpleDynamic::GetObjectsVersion() const
  1237.     {
  1238.         return ::GetObjectsVersion(this);
  1239.     }
  1240.  
  1241.     inline unsigned short TSimpleDynamic::GetObjectsMinVersion() const
  1242.     {
  1243.         return ::GetObjectsMinVersion(this);
  1244.     }
  1245.  
  1246.     inline size_t TSimpleDynamic::GetObjectsSize() const
  1247.     {
  1248.         return ((const TDynamic*)this)->GetObjectsSize();
  1249.     }
  1250.  
  1251.     inline TLibrary* TSimpleDynamic::GetObjectsLocalLibrary() const
  1252.     {
  1253.         return ((const TDynamic*)this)->GetObjectsLocalLibrary();
  1254.     }
  1255.  
  1256.     inline TLibraryFile* TSimpleDynamic::GetObjectsLocalLibraryFile() const
  1257.     {
  1258.         return ((const TDynamic*)this)->GetObjectsLocalLibraryFile();
  1259.     }
  1260.  
  1261.     inline TStandardPool* TSimpleDynamic::GetObjectsLocalPool() const
  1262.     {
  1263.         return ((const TDynamic*)this)->GetObjectsLocalPool();
  1264.     }
  1265.  
  1266.     inline void TSimpleDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1267.     {
  1268.         ((const TDynamic*)this)->SetObjectsLocalPool(pool);
  1269.     }
  1270.  
  1271.     inline Boolean TSimpleDynamic::IsDerivedFrom(const TClassID& id) const
  1272.     {
  1273.         return ((const TDynamic*)this)->IsDerivedFrom(id);
  1274.     }
  1275.     
  1276. /*    -------------------------------------------------------------------------
  1277.     Inline methods for TStdDynamic
  1278.     ------------------------------------------------------------------------- */
  1279.  
  1280.     inline const TClassID& TStdDynamic::GetObjectsClassID() const
  1281.     {
  1282.         return ((const TDynamic*)this)->GetObjectsClassID();
  1283.     }
  1284.  
  1285.     inline unsigned short TStdDynamic::GetObjectsVersion() const
  1286.     {
  1287.         return ::GetObjectsVersion(this);
  1288.     }
  1289.  
  1290.     inline unsigned short TStdDynamic::GetObjectsMinVersion() const
  1291.     {
  1292.         return ::GetObjectsMinVersion(this);
  1293.     }
  1294.  
  1295.     inline size_t TStdDynamic::GetObjectsSize() const
  1296.     {
  1297.         return ((const TDynamic*)this)->GetObjectsSize();
  1298.     }
  1299.  
  1300.     inline TLibrary* TStdDynamic::GetObjectsLocalLibrary() const
  1301.     {
  1302.         return ((const TDynamic*)this)->GetObjectsLocalLibrary();
  1303.     }
  1304.  
  1305.     inline TLibraryFile* TStdDynamic::GetObjectsLocalLibraryFile() const
  1306.     {
  1307.         return ((const TDynamic*)this)->GetObjectsLocalLibraryFile();
  1308.     }
  1309.  
  1310.     inline TStandardPool* TStdDynamic::GetObjectsLocalPool() const
  1311.     {
  1312.         return ((const TDynamic*)this)->GetObjectsLocalPool();
  1313.     }
  1314.  
  1315.     inline void TStdDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1316.     {
  1317.         ((const TDynamic*)this)->SetObjectsLocalPool(pool);
  1318.     }
  1319.     
  1320.     inline Boolean TStdDynamic::IsDerivedFrom(const TClassID& id) const
  1321.     {
  1322.         return ((const TDynamic*)this)->IsDerivedFrom(id);
  1323.     }
  1324.  
  1325. /*    -------------------------------------------------------------------------
  1326.     Inline methods for TStdSimpleDynamic
  1327.     ------------------------------------------------------------------------- */
  1328.  
  1329.     inline const TClassID& TStdSimpleDynamic::GetObjectsClassID() const
  1330.     {
  1331.         return ((const TDynamic*)this)->GetObjectsClassID();
  1332.     }
  1333.  
  1334.     inline unsigned short TStdSimpleDynamic::GetObjectsVersion() const
  1335.     {
  1336.         return ::GetObjectsVersion(this);
  1337.     }
  1338.  
  1339.     inline unsigned short TStdSimpleDynamic::GetObjectsMinVersion() const
  1340.     {
  1341.         return ::GetObjectsMinVersion(this);
  1342.     }
  1343.  
  1344.     inline size_t TStdSimpleDynamic::GetObjectsSize() const
  1345.     {
  1346.         return ((const TDynamic*)this)->GetObjectsSize();
  1347.     }
  1348.  
  1349.     inline TLibrary* TStdSimpleDynamic::GetObjectsLocalLibrary() const
  1350.     {
  1351.         return ((const TDynamic*)this)->GetObjectsLocalLibrary();
  1352.     }
  1353.  
  1354.     inline TLibraryFile* TStdSimpleDynamic::GetObjectsLocalLibraryFile() const
  1355.     {
  1356.         return ((const TDynamic*)this)->GetObjectsLocalLibraryFile();
  1357.     }
  1358.  
  1359.     inline TStandardPool* TStdSimpleDynamic::GetObjectsLocalPool() const
  1360.     {
  1361.         return ((const TDynamic*)this)->GetObjectsLocalPool();
  1362.     }
  1363.  
  1364.     inline void TStdSimpleDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1365.     {
  1366.         ((const TDynamic*)this)->SetObjectsLocalPool(pool);
  1367.     }
  1368.     
  1369.     inline Boolean TStdSimpleDynamic::IsDerivedFrom(const TClassID& id) const
  1370.     {
  1371.         return ((const TDynamic*)this)->IsDerivedFrom(id);
  1372.     }
  1373.     
  1374. #if defined(__SC__) || defined(__MRC__)
  1375.  
  1376. /*    -------------------------------------------------------------------------
  1377.     Inline methods for TSCDynamic
  1378.     ------------------------------------------------------------------------- */
  1379.  
  1380.     inline Boolean TSCDynamic::IsDerivedFrom(const TClassID& id) const
  1381.     {
  1382.         return ::IsDerivedFrom(this, id);
  1383.     }
  1384.  
  1385.     inline const TClassID& TSCDynamic::GetObjectsClassID() const
  1386.     {
  1387.         return ::GetObjectsClassID(this);
  1388.     }
  1389.  
  1390.     inline const TClassID& TSCDynamic::GetObjectsParentClassID() const
  1391.     {
  1392.         return ::GetObjectsParentClassID(this);
  1393.     }
  1394.  
  1395.     inline unsigned short TSCDynamic::GetObjectsVersion() const
  1396.     {
  1397.         return ::GetObjectsVersion(this);
  1398.     }
  1399.  
  1400.     inline unsigned short TSCDynamic::GetObjectsMinVersion() const
  1401.     {
  1402.         return ::GetObjectsMinVersion(this);
  1403.     }
  1404.  
  1405.     inline size_t TSCDynamic::GetObjectsSize() const
  1406.     {
  1407.         return ::GetObjectsSize(this);
  1408.     }
  1409.  
  1410.     inline TLibrary* TSCDynamic::GetObjectsLocalLibrary() const
  1411.     {
  1412.         return ::GetObjectsLocalLibrary(this);
  1413.     }
  1414.  
  1415.     inline TLibraryFile* TSCDynamic::GetObjectsLocalLibraryFile() const
  1416.     {
  1417.         return ::GetObjectsLocalLibraryFile(this);
  1418.     }
  1419.  
  1420.     inline TStandardPool* TSCDynamic::GetObjectsLocalPool() const
  1421.     {
  1422.         return ::GetObjectsLocalPool(this);
  1423.     }
  1424.  
  1425.     inline void TSCDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1426.     {
  1427.         ::SetObjectsLocalPool(this, pool);
  1428.     }
  1429.     
  1430. /*    -------------------------------------------------------------------------
  1431.     Inline methods for TSCSimpleDynamic
  1432.     ------------------------------------------------------------------------- */
  1433.  
  1434.     inline const TClassID& TSCSimpleDynamic::GetObjectsClassID() const
  1435.     {
  1436.         return ((const TSCDynamic*)this)->GetObjectsClassID();
  1437.     }
  1438.  
  1439.     inline const TClassID& TSCSimpleDynamic::GetObjectsParentClassID() const
  1440.     {
  1441.         return ((const TSCDynamic*)this)->GetObjectsParentClassID();
  1442.     }
  1443.  
  1444.     inline unsigned short TSCSimpleDynamic::GetObjectsVersion() const
  1445.     {
  1446.         return ::GetObjectsVersion(this);
  1447.     }
  1448.  
  1449.     inline unsigned short TSCSimpleDynamic::GetObjectsMinVersion() const
  1450.     {
  1451.         return ::GetObjectsMinVersion(this);
  1452.     }
  1453.  
  1454.     inline size_t TSCSimpleDynamic::GetObjectsSize() const
  1455.     {
  1456.         return ((const TSCDynamic*)this)->GetObjectsSize();
  1457.     }
  1458.  
  1459.     inline TLibrary* TSCSimpleDynamic::GetObjectsLocalLibrary() const
  1460.     {
  1461.         return ((const TSCDynamic*)this)->GetObjectsLocalLibrary();
  1462.     }
  1463.  
  1464.     inline TLibraryFile* TSCSimpleDynamic::GetObjectsLocalLibraryFile() const
  1465.     {
  1466.         return ((const TSCDynamic*)this)->GetObjectsLocalLibraryFile();
  1467.     }
  1468.  
  1469.     inline TStandardPool* TSCSimpleDynamic::GetObjectsLocalPool() const
  1470.     {
  1471.         return ((const TSCSimpleDynamic*)this)->GetObjectsLocalPool();
  1472.     }
  1473.  
  1474.     inline void TSCSimpleDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1475.     {
  1476.         ((const TSCSimpleDynamic*)this)->SetObjectsLocalPool(pool);
  1477.     }
  1478.  
  1479.     inline Boolean TSCSimpleDynamic::IsDerivedFrom(const TClassID& id) const
  1480.     {
  1481.         return ((const TSCSimpleDynamic*)this)->IsDerivedFrom(id);
  1482.     }
  1483.     
  1484. #endif        /* __SC__ */
  1485. #endif        /* __cplusplus */
  1486.  
  1487. /*******************************************************************************
  1488. ** EXCEPTION Handling
  1489. **
  1490. ** Some RULES:
  1491. ** 1) Never propogate a failure outside of a constructor or destructor.
  1492. **    If your constructor or destructor can call something which fails, it
  1493. **    _must_ CATCH the failure and not re-propogate it.
  1494. ** 2) Never create an object inside of a "try" block which you cannot 
  1495. **    destroy (especially an auto object).
  1496. ** 3) if you are going to just RERAISE the exception, or Fail 
  1497. **      with a different error, you must manually call the destructors 
  1498. **    of any  auto objects that are still in scope!
  1499. ** 4) Any variables that are changed inside the "try", and which are tested
  1500. **    inside a CATCH, CATCH_ALL, or FINALLY must be declared "VOLATILE" 
  1501. **      (Use the VOLATILE macro above until C++ and volatile work!)
  1502. ** 5) Never call Fail while an auto variable is in scope - it's 
  1503. **      destructor will not be called unless you call it manually.
  1504. ** 6) FINALLY is always entered after TRY unless a CATCH clause raises
  1505. **    (or re-raises) an exception (this is true even if an exception was
  1506. **    not thrown).
  1507. ********************************************************************************/
  1508.  
  1509. typedef struct TException    TException;
  1510.  
  1511. struct TException
  1512. {
  1513.     TException*            fPrev;
  1514.     size_t                fReserved;
  1515. #if GENERATINGPOWERPC
  1516.     long                fBuffer[33];
  1517. #endif
  1518. #if GENERATING68K
  1519.     long                fBuffer[12];
  1520. #endif
  1521.     char*                fMessage;
  1522.     void*                fPtr;
  1523.     OSErr                fError;
  1524. };
  1525.  
  1526. #ifdef __cplusplus
  1527. extern "C" {
  1528. #endif
  1529.  
  1530. void        PushException(TException*);
  1531. TException*    PopException(TException*);
  1532. Boolean        MatchException(TException*, long);
  1533.  
  1534. #if GENERATING68K
  1535.     #pragma parameter __D0 SetupException(__A0)
  1536.     int SetupException(long* val) =
  1537.     {
  1538.         0x43fa, 0x0008,    /* lea        *+10,a1 */
  1539.         0x48d0, 0xdefc,    /* movem.l    d2-d7/a1-a4/a6/a7,(a0) */
  1540.         0x7000            /* moveq    #0,d0 */
  1541.     };
  1542. #else
  1543.     int SetupException(long* val);
  1544. #endif
  1545.  
  1546. #ifdef __cplusplus
  1547. }
  1548. #endif
  1549.     
  1550. /*    -----------------------------------------------------------------
  1551.     Some important functions for exception handling
  1552.     ----------------------------------------------------------------- */
  1553.  
  1554. #ifdef __cplusplus
  1555. extern "C" {
  1556.     void Fail(long err, const char* msg=NULL);
  1557. }
  1558. #else
  1559.     void Fail(long err, const char* msg);
  1560. #endif
  1561.  
  1562. #ifdef __cplusplus
  1563.     inline void FailNULL(void* val, long err, const char* msg=NULL) 
  1564.     { 
  1565.         if (val == 0) 
  1566.             Fail(err, msg); 
  1567.     }
  1568. #else
  1569.     #define FailNULL(val, err, msg)        \
  1570.         if (val == 0) { Fail(err, msg); } else {}
  1571. #endif
  1572.  
  1573. #if qDebug
  1574.     #define DebugFail(err, msg)                Fail(err, msg)
  1575.     #define DebugFailNULL(ptr, err, msg)    FailNULL(ptr, err, msg)
  1576. #else
  1577.     #define DebugFail(err, msg)                Fail(err, NULL)
  1578.     #define DebugFailNULL(ptr, err, msg)    FailNULL(ptr, err, NULL)
  1579. #endif
  1580.  
  1581.  
  1582. #define ErrorCode()                 (except.fError)
  1583. #define ErrorMessage()                (except.fMessage)
  1584.  
  1585. /*    -----------------------------------------------------------------
  1586.     The RAISE/RERAISE/TRY/CATCH/CATCH_ALL/FINALLY/ENDTRY macros
  1587.     ----------------------------------------------------------------- */
  1588.  
  1589. #define RAISE(x)    Fail(x,NULL)
  1590.         
  1591. #define RERAISE        Fail(ErrorCode(), ErrorMessage())
  1592.  
  1593. #define TRY                                                 \
  1594.     {                                                        \
  1595.         Boolean        finallyUsed = false;                    \
  1596.         TException    except;                                    \
  1597.         VOLATILE(finallyUsed);                                \
  1598.         VOLATILE(except);                                    \
  1599.         PushException(&except);                                \
  1600.         if (SetupException(except.fBuffer) == 0)            \
  1601.         {
  1602.         
  1603. #define CATCH(e)                                            \
  1604.         }                                                    \
  1605.         else if (MatchException(&except, e))                \
  1606.         { 
  1607.         
  1608.         
  1609. #define CATCH_ALL                                            \
  1610.         }                                                    \
  1611.         else                                                \
  1612.         { 
  1613.         
  1614.         
  1615. #define FINALLY                                                \
  1616.         }                                                    \
  1617.         PopException(&except);                                \
  1618.         finallyUsed = true;                                    \
  1619.         {
  1620.         
  1621. #define ENDTRY                                                \
  1622.         }                                                    \
  1623.         PopException(&except);                                \
  1624.         if (finallyUsed)                                    \
  1625.             if (ErrorCode() != kNoError) RERAISE;            \
  1626.     }
  1627.  
  1628. #endif
  1629.